<?php
class Silk_Zgb_Block_Adminhtml_Warehouse_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
		protected function _prepareForm()
		{
				$session = Mage::getSingleton('admin/session');
				$roleId = $session->getUser()->getRoleId();
				//var_dump($roleId);
				$form = new Varien_Data_Form();
				$this->setForm($form);

				$warehouse = Mage::registry("warehouse_data");

				$fieldset = $form->addFieldset("zgb_form", array("legend"=>Mage::helper("zgb")->__("配送员信息")));

					$fieldset->addField("login_name", "text", array(
					"label" => Mage::helper("zgb")->__("配送员"),					
					"class" => "required-entry",
					"required" => true,
					"name" => "login_name",
					));
					$fieldset->addField("contact_phone", "text", array(
						"label" => Mage::helper("zgb")->__("联系电话"),
						"name" => "contact_phone",
						"required" => true,
						"class" => "required-entry validate-phoneLax"
					));
					$fieldset->addField("name", "text", array(
						"label" => Mage::helper("zgb")->__("名字"),
						"name" => "name",
						"required" => true,
						"class" => "required-entry"

					));
				
				
					$fieldset->addField("contact_name", "text", array(
						"label" => Mage::helper("zgb")->__("姓氏"),
						"name" => "contact_name",
						

					));

					$fieldset->addField("status", "select", array(
						"label" => Mage::helper("zgb")->__("状态"),
						"name" => "status",
						'class'    => 'required-entry',
						'required' => true,
						'values'   => array(
							 array(
							  'value'  => 1,
							  'label'  => Mage::helper('zgb')->__('启用'),
							 ),
							 array(
							  'value'  => 0,
							  'label'  => Mage::helper('zgb')->__('禁用'),
							 ),
						),
						

					));
				
					

					/*$fieldset->addField("address", "text", array(
						"label" => Mage::helper("zgb")->__("联系地址"),
						"name" => "address",
						"required" => true,
						"class" => "required-entry"
					));*/

					/*$provinces = array();
		            $collection = Mage::getModel('directory/region')->getCollection()->addFieldToFilter('country_id', array('eq'=>'CN'));
		            $provinces[] = array('value'=>'','label'=>'-请选择-');
		            foreach($collection as $region)
		            {
		                $provinces[] = array('value'=>$region->getId(),'label'=>$region->getName());
		            }

		            $fieldset->addField('province_id','select', array(
		                'name' => 'province_id',
		                'label' => '省',
		                'required'  => true,
		                'value' => '',
		                'values' => $provinces,
		            ));

		            $citys = array();
		            $collection = Mage::getModel('chinaarea/city')->getCollection()->addFieldToFilter('region_id',array('eq'=>$warehouse->getProvinceId()));
		            $citys[] = array('value'=>'','label'=>'-请选择-');
		            foreach($collection as $city)
		            {
		                $citys[] = array('value'=>$city->getId(), 'label'=>$city->getDefaultName());
		            }

		            $fieldset->addField('city_id','select', array(
		                'name' => 'city_id',
		                'label' => '市',
		                'required'  => true,
		                'value' => '',
		                'values' => $citys,
		                'after_element_html' => '
		                <script type="text/javascript">
		                </script>
		                ',
		            ));

		            $areas = array();
		            $collection = Mage::getModel('chinaarea/area')->getCollection()->addFieldToFilter('city_id',array('eq'=>$warehouse->getCityId()));
		            $areas[] = array('value'=>'','label'=>'-请选择-');
		            foreach($collection as $area)
		            {
		                $areas[] = array('value'=>$area->getId(), 'label'=>$area->getDefaultName());
		            }

		            $fieldset->addField('area_id','select', array(
		                'name' => 'area_id',
		                'label' => '区县',
		                'required'  => true,
		                'value' => '',
		                'values' => $areas,
		            ));

		            if($roleId==1)
		            {
						$dealers = array();
						$collection = Mage::getModel('zgb/dealer')->getCollection();
						$dealers[] = array();
						foreach($collection as $dealer)
						{
							$dealers[] = array('label'=>$dealer->getName(), 'value'=>$dealer->getId());
						}

						$fieldset->addField(
			                'dealer_id',
			                'select',
			                array(
			                     'name'     => 'dealer_id',
			                     'label'    => Mage::helper('cms')->__('经销商'),
			                     'title'    => Mage::helper('cms')->__('经销商'),
			                     'required' => true,
			                     'values'   => $dealers,
			                )
			            );
					}
					else
					{
						if(!$warehouse->getId())
						{
							$model = Mage::getModel('zgb/dealer')->loadByAdminId($session->getUser()->getId());
							$fieldset->addField('dealer_id', 'hidden', array(
				                'name'  => 'dealer_id',
				                'value' => $model->getId()
				            ));
			            }
					}*/
					

					$fieldset->addField("note", "textarea", array(
						"label" => Mage::helper("zgb")->__("备注"),
						"name" => "note",
					));

				$fieldset = $form->addFieldset("zgb_login_form", array("legend"=>Mage::helper("zgb")->__("配送员登录密码")));

					$fieldset->addField("password", "password", array(
					"label" => Mage::helper("zgb")->__("密码"),					
					"class" => "required-entry validate-admin-password",
					"required" => true,
					"name" => "password",
					));
					
					

				if (Mage::getSingleton("adminhtml/session")->getWarehouseData())
				{
					$form->setValues(Mage::getSingleton("adminhtml/session")->getWarehouseData());
					Mage::getSingleton("adminhtml/session")->setWarehouseData(null);
				} 
				elseif(Mage::registry("warehouse_data")) {
				    $form->setValues(Mage::registry("warehouse_data")->getData());
				}
				return parent::_prepareForm();
		}
		
		
}
